//品牌控制层
app.controller('baseController', function ($scope) {

    //重新加载列表 数据
    $scope.reloadList = function () {
        if (getUrlSearch('qq') != null) {
            $scope.searchEntity.qq = getUrlSearch('qq');
        }
        //切换页码
        $scope.search($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
    }

    //分页控件配置
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 10,
        itemsPerPage: 10,
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function () {
            $scope.reloadList();//重新加载
        }
    };

    $scope.selectIds = [];//选中的ID集合

    //更新复选
    $scope.updateSelection = function ($event, id) {
        if ($event.target.checked) {//如果是被选中,则增加到数组
            $scope.selectIds.push(id);
        } else {
            var idx = $scope.selectIds.indexOf(id);
            $scope.selectIds.splice(idx, 1);//删除
        }
    }

    $scope.addfavorite = function () {
        if ($scope.searchEntity.qq != null) {
            alert("请保存载入后的网页为书签");
            window.location.href = '/admin/tieba.html?qq=' + $scope.searchEntity.qq;
        } else {
            alert("请查询QQ后保存再点书签进入保存");
        }
    }


});

function getUrlSearch(name) {
    // 未传参，返回空
    if (!name) return null;
    // 查询参数：先通过search取值，如果取不到就通过hash来取
    var after = window.location.search;
    after = after.substr(1) || window.location.hash.split('?')[1];
    // 地址栏URL没有查询参数，返回空
    if (!after) return null;
    // 如果查询参数中没有"name"，返回空
    if (after.indexOf(name) === -1) return null;

    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
    // 当地址栏参数存在中文时，需要解码，不然会乱码
    var r = decodeURI(after).match(reg);
    // 如果url中"name"没有值，返回空
    if (!r) return null;
    return r[2];
}

/**
 * 获取指定cookie字段值
 * @param name
 * @returns {string|null}
 */
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}

/*
$httpProvider.interceptors.push(['$q','$rootScope',function($q,$rootScope){
    return {
        'request': function(config){
            $rootScope.loading = true;
            return $q.resolve(config);
        },
        'response': function(response){
            $rootScope.loading = true; //f
            return $q.resolve(response);
        },
        'requestError':function(rejection){
            $rootScope.loading = true; //f
            return $q.reject(rejection);
        },
        'responseError':function(rejection){
            $rootScope.loading = true; //f
            return $q.reject(rejection);
        }
    }
}]);
*/
